<?php

class Uwd extends CI_Model {

    function auth($data) {
        $this->db->where('username', $data['username']);
        $this->db->where('password', $data['password']);
        $data = $this->db->get('user');
        if ($data->num_rows == 1) {
            return $data->row();
        }
    }

    function nama($id) {
        $this->db->where('username', $id);
        $data = $this->db->get('dosen');
        return $data->result();
    }

    function mhs_nama($id) {
        $this->db->where('username', $id);
        $data = $this->db->get('mahasiswa');
        return $data->result();
    }

    function nama_mhs($us) {
        $this->db->where('username', $us);
        $data = $this->db->get('mahasiswa');
        return $data->row();
    }

    function profile($usr) {
        $this->db->where('username', $usr);
        $data = $this->db->get('dosen');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function profile_upd($id, $data) {
        $this->db->where('username', $id);
        $this->db->update('dosen', $data);
    }

    function passlama($id, $lama) {
        $this->db->where('username', $id);
        $this->db->where('password', $lama);
        $data = $this->db->get('user');
        if ($data->num_rows > 0) {
            return TRUE;
        } else {
            return FALSE;
        }
    }

    function passbaru($id, $pass) {
        $this->db->where('username', $id);
        $this->db->update('user', $pass);
    }

    function matkul() {
        $this->db->order_by('matkul');
        $data = $this->db->get('matkul');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function upload($input) {
        $this->db->insert('files', $input);
    }

    function materi($id, $config) {
        $this->db->where('dosen_id', $id);
        $data = $this->db->get('vmateri', $config['per_page'], $config['uri']);
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function get_link($id) {
        $this->db->where('hash', $id);
        $data = $this->db->get('vmateri');
        if ($data->num_rows > 0) {
            return $data->row();
        }
    }

    function hitung($id, $dat) {
        $this->db->where('hash', $id);
        $this->db->update('files', $dat);
    }

    function add_dosen($data) {
        $this->db->insert('dosen', $data);
    }

    function add_user($usr) {
        $this->db->insert('user', $usr);
    }

    function count_dosen() {
        $data = $this->db->get('dosen');
        if ($data->num_rows > 0) {
            return $data->num_rows();
        }
    }

    function list_dosen($config) {
        $this->db->order_by('nama');
        $data = $this->db->get('dosen', $config['per_page'], $config['uri']);
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function count_matkul() {
        $data = $this->db->get('matkul');
        if ($data->num_rows > 0) {
            return $data->num_rows();
        }
    }

    function count_materi($id) {
        $this->db->where('dosen_id', $id);
        $data = $this->db->get('files');
        if ($data->num_rows > 0) {
            return $data->num_rows();
        }
    }

    function list_matkul($config) {
        $this->db->order_by('matkul');
        $data = $this->db->get('matkul', $config['per_page'], $config['uri']);
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function add_matkul($mtk) {
        $this->db->insert('matkul', $mtk);
    }

    function del_dosen($id) {
        $this->db->where('username', $id);
        $this->db->delete('dosen');
    }

    function del_matkul($id) {
        $this->db->where('id', $id);
        $this->db->delete('matkul');
    }

    function get_matkul($id) {
        $this->db->where('id', $id);
        $data = $this->db->get('matkul');
        return $data->row();
    }

    function upd_matkul($id, $data) {
        $this->db->where('id', $id);
        $this->db->update('matkul', $data);
    }

    function new_materi() {
        $this->db->order_by('date', 'desc');
        $data = $this->db->get('vmateri');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function top_download() {
        $this->db->order_by('download', 'desc');
        $this->db->limit(10);
        $data = $this->db->get('vmateri');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function top_matkul() {
        $this->db->group_by('matkul_id');
        $this->db->limit(10);
        $data = $this->db->get('vmateri');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function by_matkul($id) {
        $this->db->where('matkul', $id);
        $data = $this->db->get('vmateri');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function detail_materi($id) {
        $this->db->where('hash', $id);
        $data = $this->db->get('vmateri');
        if ($data->num_rows > 0) {
            return $data->row();
        }
    }

    function materi_dosen($id) {
        $this->db->select('nama');
        $this->db->where('matkul', $id);
        $this->db->group_by('nama');
        $this->db->order_by('nama');
        $data = $this->db->get('vmateri');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function mat_dosen($id) {
        $this->db->where('nama', $id);
        $data = $this->db->get('vmateri');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function matkul_ampu($id) {
        $this->db->where('nama', $id);
        $this->db->group_by('matkul');
        $data = $this->db->get('vmateri');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function materi_lain($dosen) {
        $this->db->where('nama', $dosen);
        $this->db->limit(10);
        $this->db->order_by('date');
        $data = $this->db->get('vmateri');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function dftr_dosen() {
        $this->db->order_by('nama');
        $data = $this->db->get('dosen');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function cari($id) {
        $this->db->like('matkul', $id);
        $this->db->or_like('judul', $id);
        $this->db->or_like('nama', $id);
        $data = $this->db->get('vmateri');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
